package com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.detail.*;
import com.fingard.xml.XmlTextWriter;

/**
 * 海外--付款元素获取响应ATS
 */
public class RetAtsCJFrgCurrGetVal extends RetAtsBase {

    private int writeRdCount = 0;

    public RetAtsCJFrgCurrGetVal(ReqRespHeader p_header) {
        retHeader = p_header;
        retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
    }

    public void writeRetXml(String xml) throws Exception{
        retXmlWriter.directWrite(xml);
    }

    public int getWrittenRdCount() {
        return writeRdCount;
    }

    public void writeRetDetail(RetAtsCJFrgCurrGetValDetail p_retDetail) throws Exception {
        writeRdCount++;
        if (writeRdCount == 1) {
            if (!hasWrittenRespCode) {
                writeRespCode("0");
            }
            if (!hasWrittenRespInfo) {
                writeRespInfo("");
            }
        }
        retXmlWriter.writeStartElement("DetailRecord");
        retXmlWriter.writeElementString("BankType",p_retDetail.bankType);
        retXmlWriter.writeElementString("PayBankCountryCode",p_retDetail.payBankCountryCode);
        retXmlWriter.writeElementString("MethodName",p_retDetail.methodName);
        retXmlWriter.writeElementString("PayCurrency",p_retDetail.payCurrency);
        retXmlWriter.writeElementString("BeneBankCountry",p_retDetail.beneBankCountry);
        retXmlWriter.writeElementString("Version",p_retDetail.version);
        if(p_retDetail.template!=null && p_retDetail.template.size()>0){
            for (FrgCurrSingleTemplate template:p_retDetail.template){
                retXmlWriter.writeStartElement("Template");
                retXmlWriter.writeElementString("TemplateName",template.templateName);
                retXmlWriter.writeElementString("TemplateDescZh",template.templateDescZh);
                retXmlWriter.writeElementString("TemplateDescEn",template.templateDescEn);
                if(template.field!=null && template.field.size()>0){
                    for(FrgCurrSingleField rule:template.field){
                        retXmlWriter.writeStartElement("Field");
                        retXmlWriter.writeElementString("Name",rule.name);
                        retXmlWriter.writeElementString("Reqiured",rule.reqiured);
                        retXmlWriter.writeElementString("Enums",rule.enums);
                        retXmlWriter.writeElementString("CheckRule",rule.checkRule);
                        retXmlWriter.writeElementString("Default",rule.Default);
                        retXmlWriter.writeElementString("CharSetCheck",rule.charSetCheck);
                        retXmlWriter.writeElementString("Type",rule.type);
                        retXmlWriter.writeElementString("Regex",rule.regex);
                        retXmlWriter.writeEndElement();
                    }
                }
                retXmlWriter.writeEndElement();
            }
        }
        retXmlWriter.writeEndElement();

    }
}
